package cn.piesat.client.constant.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * 客户端记录编号枚举类
 * 因为算法生成的结果编号与平台编号冲突，这里需要将算法生成的结果编号algorithmResultNumber转成记录编号recordNumber
 */
public enum ClientRecordEnum {

    //任务正在运行(此算法结果编码-1是无效值,充当占位)
    RUNNING(1,"-1"),
    //算法：成功
    SUCCESS(2,"0"),
    //算法：失败
    FAIL(3,"1"),
    //算法：传入参数异常
    PARAMETER_ERR(4,"2"),
    //算法：时间异常
    FILE_TIME_ERR(5,"3"),
    //算法：区域异常
    AREA_ERR(6,"4"),
    //算法：重做
    REDO(7,"9"),
    //未知错误
    UNKNOWN(-1,null);

    /**
     * 记录编号
     */
    private Integer recordNumber;

    /**
     * 结果编号
     */
    private String algorithmResultNumber;

    ClientRecordEnum(Integer recordNumber, String algorithmResultNumber) {
        this.recordNumber = recordNumber;
        this.algorithmResultNumber = algorithmResultNumber;
    }

    public Integer getRecordNumber() {
        return recordNumber;
    }

    public String getAlgorithmResultNumber() {
        return algorithmResultNumber;
    }

    public static ClientRecordEnum getClientRecordEnumOfResultNumber(String resultNumber){
        if(StringUtils.isNotBlank(resultNumber)){
            for (ClientRecordEnum value : ClientRecordEnum.values()) {
                if(value.getAlgorithmResultNumber().equals(resultNumber)){
                    return value;
                }
            }
        }
        return ClientRecordEnum.UNKNOWN;
    }
}
